<div id="app">
  <div class="p2 flex">
    <a href="javascript:history.go(-1)" class="weui-btn weui-btn_mini weui-btn_default"> 返回 </a>
    <div style="flex: 1"></div>
    <div class="weui-btn weui-btn_mini weui-btn_warn" @click="resetSetting">恢复系统默认</div>
  </div>

  <div>
    <div class="weui-cells__title">邀请成功话术</div>
    <div class="weui-cells">
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <textarea
            class="weui-textarea"
            rows="4"
            v-model="setting.invitetips"
            placeholder="请输入邀请成功话术"
          ></textarea>
        </div>
      </div>
    </div>

    <div class="weui-cells__title">签到成功话术</div>
    <div class="weui-cells">
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <textarea
            class="weui-textarea"
            rows="4"
            v-model="setting.signtips"
            placeholder="请输入签到成功话术"
          ></textarea>
        </div>
      </div>
    </div>

    <div class="center my2">
      <button class="weui-btn weui-btn_primary" @click="saveSetting">保存</button>
    </div>
  </div>

  <div class="mt4 rounded2 m1 p1 bg-silver">
    <div class="font-13 bold">帮助文档</div>
    <div class="font-12 pt1"><span class="bold">邀请话术可用插入值:</span> {{inviteargs}}</div>
    <div class="font-12 pt1"><span class="bold">签到话术可用插入值:</span> {{signargs}}</div>
  </div>
</div>

<script>
  new Vue({
    el: "#app",
    data: function () {
      return {
        inviteargs: "{{邀请积分}}, {{现有积分}}, {{兑换地址}}",
        signargs: "{{签到积分}}, {{现有积分}}, {{兑换地址}}",
        setting: {},
      };
    },
    created: function () {
      this.refresh();
    },
    methods: {
      refresh: function () {
        let that = this;
        axios.get("/client/setting").then(function (res) {
          that.setting = res.data.setting;
        });
      },
      saveSetting: function () {
        let that = this;
        axios
          .post("/client/setting", { setting: this.setting })
          .then(function () {
            weui.toast("保存成功", 300);
            that.setting = res.data.setting;
          });
      },
      resetSetting: function () {
        let that = this;
        axios.post("/client/setting/reset").then(function () {
          weui.toast("恢复系统默认", 300);
          that.refresh();
        });
      },
    },
  });
</script>
